package com.blog.controller;

import com.blog.bean.StayWord;
import com.blog.service.StayWordService;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Map;

@Controller
public class StayWordController {

    @Resource
    private StayWordService stayWordService;

    /**
     * 留言页
     *
     * @return
     */
    @RequestMapping("/stayWord")
    public String stayWord() {
        return "stay-word";
    }

    /**
     * 添加留言
     *
     * @param stayWord
     * @return
     */
    @RequestMapping("/addStayWord")
    @ResponseBody
    public Object addStayWord(StayWord stayWord) {
        Map<Object, Object> map = new HashMap<>();
        stayWord.setStayWordTime(new Timestamp(System.currentTimeMillis()));
        stayWord.setStayWordState(1);
        int count = stayWordService.insertSelective(stayWord);
        if (count > 0) {
            map.put("result", "success");
        }
        return map;
    }
}
